﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace ElingOA6_Admin_DSJCJ.BLL
{
    /// <summary>
    /// 业务逻辑类ad 的摘要说明。
    /// </summary>
    public class Ad
    {
        /// <summary>
        /// Dal定义的便利
        /// </summary>
        private readonly DAL.Ad dal = new DAL.Ad();

        /// <summary>
        /// 获取全屏广告的个数
        /// </summary>
        /// <param name="strEntityNo">公司编号</param>
        /// <returns>全屏广告的个数</returns>
        public int GetQPCount(string strEntityNo)
        {
            return dal.GetQPCount(strEntityNo);
        }
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        /// <creator>chenly</creator>
        /// <date>2013-7-12</date>
        /// <param name="fAdcd">广告编号</param>
        /// <param name="fEntityNo">公司编号</param>
        /// <returns>是否存在</returns>
        public bool Exists(string fAdcd, string fEntityNo)
        {
            return dal.Exists(fAdcd, fEntityNo);
        }
        /// <summary>
        /// 更新
        /// </summary>
        /// <creator>chenly</creator>
        /// <date>2012-11-15</date>
        /// <param name="model">一个model对象</param>
        public void Update(Model.Ad model)
        {
            dal.Update(model);
        }
        ///// <summary>
        ///// 更新
        ///// </summary>
        ///// <creator>chenly</creator>
        ///// <date>2012-11-15</date>
        ///// <param name="model">一个model对象</param>
        //public void UpdateImg(Model.Ad model)
        //{
        //    dal.UpdateImg(model);
        //}
        /// <summary>
        /// 保存
        /// <creator>chenly</creator>
        /// <date>2013-7-12</date>
        /// </summary>
        /// <param name="model">model</param>
        public void Add(Model.Ad ad)
        {
            dal.Add(ad);
        }

        /// <summary>
        /// 获得多条图片存放路径
        /// </summary>
        /// <param name="strAdCds">编号字符</param>
        /// <param name="strEntityNo">公司编号</param>
        /// <returns>集合</returns>
        public List<string> GetManySrvName(string[] strAdCds, string strEntityNo)
        {
            return dal.GetSrvName(strAdCds, strEntityNo);
        }

        /// <summary>
        /// 获得多条图片存放路径
        /// </summary>
        /// <param name="strAdCds">编号字符</param>
        /// <param name="strEntityNo">编号字符</param>
        /// <returns>编号字符</returns>
        public List<string> GetSrvName(string strAdCds, string strEntityNo)
        {
            return dal.GetSrvName(strAdCds, strEntityNo);
        }

        // <summary>
        /// 获取左对联广告的个数
        /// </summary>
        /// <creator>chenly</creator>
        /// <date>2013-7-9</date>
        /// <param name="strEntityNo">公司编号</param>
        /// <returns>左对联广告的个数</returns>
        public int GetLeftDlCount(string strEntityNo)
        {
            return dal.GetLeftDlCount(strEntityNo);
        }

        /// <summary>
        /// 获取右对联广告的个数
        /// </summary>
        /// <creator>chenly</creator>
        /// <date>2013-7-9</date>
        /// <param name="strEntityNo">公司编号</param>
        /// <returns>右对联广告的个数</returns>
        public int GetRightDlCount(string strEntityNo)
        {
            return dal.GetRightDlCount(strEntityNo);
        }
        /// <summary>
        ///  获得数据列表
        /// <creator>chenly</creator>
        /// <date>2013-7-9</date>
        /// </summary>
        /// <returns>列表</returns>

        public List<ElingOA6_Admin_DSJCJ.Model.Ad> GetModelAdList()
        {
            DataSet ds = dal.GetAdList();
            return DataTableToListAd(ds.Tables[0]);
        }

        /// <summary>
        /// 批量删除数据 
        /// <creator>chenly</creator>
        /// <date>2013-7-11</date>
        /// </summary>
        /// <param name="empNoArray">编号数组</param>
        /// <param name="entityNo">公司编号</param>
        public void DelManyAd(string[] empNoArray, string entityNo)
        {
            dal.DelManyAd(empNoArray, entityNo);
        }

        /// <summary>
        /// 删除数据 
        /// <creator>chenly</creator>
        /// <date>2013-7-11</date>
        /// </summary>
        /// <param name="empNo">编号</param>
        /// <param name="entityNo">公司编号</param>
        public void DelAd(string adNo, string entityNo)
        {
            dal.DelAd(adNo, entityNo);
        }

        /// <summary>
        /// 获取图片二进制流
        /// <creator>chenly</creator>
        /// <date>2012-11-16</date>
        /// </summary>
        /// <param name="adNo">编号</param>
        /// <param name="entityNo">公司编号</param>
        /// <returns>二进制流</returns>

        public byte[] GetPhoto(string adNo, string entityNo)
        {
            return dal.GetPhoto(adNo, entityNo);
        }

        /// <summary>
        /// 更新相关信息
        /// <creator>chenly</creator>
        /// <date>2012-7-13</date>
        /// </summary>
        /// <param name="entityNo">公司编号</param>
        /// <param name="fAdContent">广告内容</param>
        /// <param name="fSvrFileName">地址</param>
        /// <param name="fAdType">广告类型</param>
        /// <param name="fOldFileName">原来的名字</param>
        public void UpdateFile(string entityNo, byte[] fAdContent, string fSvrFileName,
            string fAdType, string fOldFileName)
        {
            dal.UpdateFile(entityNo, fAdContent, fSvrFileName, fAdType, fOldFileName);
        }

        /// <summary>
        /// 得到一个对象实体
        /// <creator>chenly</creator>
        /// <date>2013-7-11</date>
        /// </summary>
        /// <param name="fEntityNo">公司编号</param>
        /// <param name="fAdNo">广告编号</param>
        /// <returns>返回Model</returns>
        public Model.Ad GetModel(string fEntityNo, string fAdNo)
        {

            return dal.GetModel(fEntityNo, fAdNo);
        }


        
        /// <summary>
        ///  获得数据列表
        /// <summary>
        /// <creator>chenly</creator>
        /// <date>2013-7-9</date>
        /// </summary>
        /// <param name="dt">一张DataTable</param>
        /// <returns>返回Model</returns>
        public List<Model.Ad> DataTableToListAd(DataTable dt)
        {
            List<Model.Ad> modelList = new List<Model.Ad>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Model.Ad model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Model.Ad();

                    if (dt.Rows[n]["FAdcd"] != null && dt.Rows[n]["FAdcd"].ToString() != "")
                    {
                        model.FAdcd = dt.Rows[n]["FAdcd"].ToString();
                    } if (dt.Rows[n]["FEntityNo"] != null && dt.Rows[n]["FEntityNo"].ToString() != "")
                    {
                        model.FEntityNo = dt.Rows[n]["FEntityNo"].ToString();
                    }
                    if (dt.Rows[n]["FAdName"] != null && dt.Rows[n]["FAdName"].ToString() != "")
                    {
                        model.FAdName = dt.Rows[n]["FAdName"].ToString();
                    }
                    if (dt.Rows[n]["FAdProp"] != null && dt.Rows[n]["FAdProp"].ToString() != "")
                    {
                        model.FAdProp = dt.Rows[n]["FAdProp"].ToString();
                    }
                    if (dt.Rows[n]["FDataType"] != null && dt.Rows[n]["FDataType"].ToString() != "")
                    {
                        model.FDataType = dt.Rows[n]["FDataType"].ToString();
                    }
                    if (dt.Rows[n]["FOldFileName"] != null && dt.Rows[n]["FOldFileName"].ToString() != "")
                    {
                        model.FOldFileName = dt.Rows[n]["FOldFileName"].ToString();
                    }
                    if (dt.Rows[n]["FSvrFileName"] != null && dt.Rows[n]["FSvrFileName"].ToString() != "")
                    {
                        model.FSvrFileName = dt.Rows[n]["FSvrFileName"].ToString();
                    }

                    if (dt.Rows[n]["FAdUrl"] != null && dt.Rows[n]["FAdUrl"].ToString() != "")
                    {
                        model.FAdUrl = dt.Rows[n]["FAdUrl"].ToString();
                    }
                    if (dt.Rows[n]["FIsUse"] != null && dt.Rows[n]["FIsUse"].ToString() != "")
                    {
                        model.FIsUse = decimal.Parse(dt.Rows[n]["FIsUse"].ToString());
                    }
                    if (dt.Rows[n]["FAdWidth"] != null && dt.Rows[n]["FAdWidth"].ToString() != "")
                    {
                        model.FAdWidth = int.Parse(dt.Rows[n]["FAdWidth"].ToString());
                    }
                    if (dt.Rows[n]["FAdHeight"] != null && dt.Rows[n]["FAdHeight"].ToString() != "")
                    {
                        model.FAdHeight =int.Parse(dt.Rows[n]["FAdHeight"].ToString());
                    }


                    modelList.Add(model);
                }
            }
            return modelList;
        }


        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Model.Ad> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<ElingOA6_Admin_DSJCJ.Model.Ad> DataTableToList(DataTable dt)
        {
            List<ElingOA6_Admin_DSJCJ.Model.Ad> modelList = new List<ElingOA6_Admin_DSJCJ.Model.Ad>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                ElingOA6_Admin_DSJCJ.Model.Ad model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = dal.DataRowToModel(dt.Rows[n]);
                    if (model != null)
                    {
                        modelList.Add(model);
                    }
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Model.Ad> GetModelList(int top, string strWhere, string filedOrder)
        {
            DataSet ds = dal.GetList(top, strWhere, filedOrder);
            return DataTableToList(ds.Tables[0]);
        }

    }
}
